<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    const source = [
      {
        id: 3,
        name: "test2",
      },
      {},
      {
        id: "4",
        name: "test1",
      },
      {
        id: 6,
        name: "test3",
      },
      {
        id: () => {},
        name: "test7",
      },
      {
        id: 2,
        name: "test5",
      },
    ];
    // 过滤出id为number类型的
    let source1 = source.filter((item) => {
      return typeof item.id == "number";
    });
    console.log(source1);
    // 排序
     let arr= source1.sort((a, b) => {
     return a.id - b.id;
    });
    console.log(arr);
     // 排序
     let arr1= source1.sort((a, b) => {
     return b.id - a.id;
    });
    console.log(arr1);
  </script>
</html>
